import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:lottie/lottie.dart';

import '../../../tools_base/widget/net_image_widget.dart';

///用户头像（包括VIP）
class HeaderWidget extends StatelessWidget {
  final String? headPath;

  final double? headWidth;

  final double? headHeight;

  //vip显示的高度
  final double? borderHeight;

  final Widget? defaultHead;

  final bool? superUser;

  final double? levelSize;

  final double? positionedSize;

  //点击头像
  final VoidCallback? tabCallback;

  final bool? isCertified; //是否认证

  HeaderWidget({
    super.key,
    required this.headPath,
    required this.superUser,
    required this.headWidth,
    required this.headHeight,
    this.levelSize = 16,
    this.positionedSize = 2,
    this.isCertified = false,
    this.borderHeight,
    this.defaultHead,
    this.tabCallback,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: tabCallback,
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(borderHeight ?? 0),
            decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(60.r)),
            child: ClipOval(
              child: NetworkImageLoader(
                imageUrl: headPath ?? "",
                width: headWidth,
                height: headHeight,
                placeHolderWidget: defaultHead ??
                    Image.asset(
                      "place_holder_logo.webp".commonImgPath,
                      fit: BoxFit.cover,
                      width: headWidth,
                      height: headHeight,
                    ),
              ),
            ),
          ),

          if (isCertified ?? false)
            Container(
              width: headWidth ?? 80.w,
              height: headHeight ?? 80.w,
              decoration: BoxDecoration(
                border: Border.all(width: 1, color: Color(0xffd82d0b)),
                shape: BoxShape.circle,
              ),
            ),
          if (superUser ?? false)
            Positioned(
              bottom: positionedSize ?? 0,
              right: positionedSize ?? 0,
              child: ClipOval(
                child: Stack(
                  children: [
                    Image.asset(
                      "mine_big_vip.png".mineImgPath,
                      width: levelSize ?? 22,
                      height: levelSize ?? 22,
                    ),
                    Lottie.asset(
                      "assets/flare/dh.json",
                      width: levelSize ?? 22,
                      height: levelSize ?? 22,
                    ),
                  ],
                ),
              ),
            ),

          ///设置认证头像
          if (isCertified ?? false)
            Positioned(
              top: -5,
              child: Container(
                child: Image.asset("ic_user_head_mark.png".mineImgPath, width: headWidth, fit: BoxFit.fitWidth),
              ),
            ),
        ],
      ),
    );
  }
}
